package xyz.hujf.myThreadPool;

import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.*;

/**
 * @author Hujf
 * @title: ThreadPoolTest2
 * @date 2021-05-05 14:25
 * @description: TODO
 */
public class ThreadPoolTest2 {
    static class LocalVariable{
        private Long[] a =new Long[1024*1024];
    }

    final static ExecutorService poolEx = new ThreadPoolExecutor(4,4,1L, TimeUnit.SECONDS,new LinkedBlockingQueue<>());
    final static ThreadLocal<LocalVariable> threadLocal = new ThreadLocal<>();

    public static void main(String[] args) throws InterruptedException {
        for(int i=0;i<50;i++){
            poolEx.execute(()->{
                threadLocal.set(new LocalVariable());
                System.out.println("use local value");
                threadLocal.remove();
            });
            Thread.sleep(1000);
        }
        System.out.println("pool ececute over ");

    }

//    public static void main(String args[]){ // jdk1.8新特性哦
//        HashMap<String,String> map = new HashMap<>();
//        map.put("1","is map");
//        map.put("2","contains a mapping");
//        map.put("3","specified");
//        map.put("4","inappropriate");
//        map.computeIfAbsent("5", ThreadPoolTest2::apply);
//        System.out.println(map.get("5"));
//    }
//
//    private static String apply(String v) {
//        return "is 5";
//    }
}

